package controller

import (
	"ollama-go/dto"
	"ollama-go/entity"
	"ollama-go/query"
	"ollama-go/service"

	"github.com/androidsr/sc-go/model"
	"github.com/androidsr/sc-go/sgin"
	"github.com/gin-gonic/gin"
)

func init() {
	sgin.AddRouter(TsTaskStepController{
		tsTaskStepService: service.NewTsTaskStepService(),
	})
}

type TsTaskStepController struct {
	tsTaskStepService *service.TsTaskStepService
}

// 查询
// @Router [get] [/tstaskstep/:id]
func (m TsTaskStepController) Get(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.tsTaskStepService.Get(id)
}

// 增加
// @Router [post] [/tstaskstep]
func (m TsTaskStepController) Save(c *gin.Context, dto *dto.TsTaskStepDTO) any {
	dto.Id = ""
	return m.tsTaskStepService.Save(dto)
}

// 修改
// @Router [put] [/tstaskstep/edit]
func (m TsTaskStepController) UpdateById(c *gin.Context, dto *dto.TsTaskStepDTO) any {
	if dto.Id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.tsTaskStepService.UpdateById(dto)

}

// 删除
// @Router [delete] [/tstaskstep/:id]
func (m TsTaskStepController) DeleteById(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.tsTaskStepService.DeleteById(id)
}

// 查询列表
// @Router [post] [/tstaskstep/page]
func (m TsTaskStepController) QueryPage(c *gin.Context, query *query.TsTaskStepQueryDTO) any {
	return m.tsTaskStepService.QueryPage(query)
}

// 分页下拉
// @Router [post] [/tstaskstep/list]
func (m TsTaskStepController) QuerySelect(c *gin.Context, query *model.SelectQueryDTO) any {
	return m.tsTaskStepService.QueryList(query)
}

// 按任务ID查询
// @Router [get] [/tstaskstep/findByTaskId/:taskId]
func (m TsTaskStepController) FindByTaskId(c *gin.Context) any {
	taskId := c.Param("taskId")
	if taskId == "" {
		return model.NewFailDefault("taskId不能为空")
	}
	data, err := m.tsTaskStepService.FindByTaskId(taskId)
	if err != nil {
		return model.NewFailDefault(err.Error())
	}
	return model.NewOK(data)
}

// 按任务ID查询
// @Router [post] [/tstaskstep/batchAdd/:taskId]
func (m TsTaskStepController) BatchAdd(c *gin.Context, data *[]entity.TsTaskStep) any {
	taskId := c.Param("taskId")
	if taskId == "" {
		return model.NewFailDefault("taskId不能为空")
	}
	err := m.tsTaskStepService.BatchAdd(taskId, data)
	if err != nil {
		return model.NewFailDefault(err.Error())
	}
	return model.NewOK(true)
}
